<template>
  <div>
    <el-table :key='tableKey' :data="list" v-loading.body="listLoading" border fit highlight-current-row style="width: 100%">

      <el-table-column v-for="(item, index) in tableCol" :key="item.id" align="center" :label="item.label" :render-header="item.renderHeader" :formatter="item.formatter">
        <template scope="scope">
          <span>{{scope.row[item.key]}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template scope="scope">
          <span>
            <el-button v-for="item in itemAction" :type="item.type" :key="item.id" size="small">
              {{item.actionName}}
            </el-button>
          </span>
        </template>
      </el-table-column>

      <!--<el-table-column align="center" label="序号" width="65">-->
        <!--<template scope="scope">-->
          <!--<span>{{scope.row.id}}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->

      <!--<el-table-column width="180px" align="center" label="时间">-->
        <!--<template scope="scope">-->
          <!--<span>{{scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->

      <!--<el-table-column min-width="300px" label="标题">-->
        <!--<template scope="scope">-->
          <!--<span class="link-type">{{scope.row.title}}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->

      <!--<el-table-column width="110px" align="center" label="作者">-->
        <!--<template scope="scope">-->
          <!--<span>{{scope.row.author}}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!---->

      <!--<el-table-column width="80px" label="重要性">-->
        <!--<template scope="scope">-->
          <!--<icon-svg v-for="n in +scope.row.importance" icon-class="wujiaoxing" class="meta-item__icon" :key="n"></icon-svg>-->
        <!--</template>-->
      <!--</el-table-column>-->

      <!--<el-table-column align="center" label="还有这种操作？" width="200">-->
        <!--<template scope="scope">-->
          <!--<el-button size="small" @click="handleUpdate(scope.row)">编辑</el-button>-->
          <!--<el-button size="small" @click="handleUpdate(scope.row)">换卡</el-button>-->
          <!--<el-button size="small" @click="handleUpdate(scope.row)">停卡</el-button>-->
        <!--</template>-->
      <!--</el-table-column>-->

    </el-table>

    <!--这是分页-->
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.page"
                     :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import dataTable from 'components/dataTable/index';
  import { fetchList } from 'api/article_table';
  import { parseTime } from 'utils';

  export default {
    name: 'table_demo',
    components:{
      dataTable
    },
    props: {
      tableCol: {
        type: Array,
        label: {
          type: String
        },
        key: {
          type: String
        }
      },
      itemAction: {
        type: Array
      }
    },
    data() {
      return {
//        列表数据
        list: null,
//        页码
        total: null,
//        顶部loading条
        listLoading: true,
//        搜索条件
        listQuery: {
          page: 1,
          limit: 20,
          importance: undefined,
          title: undefined,
          type: undefined,
          sort: '+id'
        },
        dialogFormVisible: false,
        dialogPvVisible: false,
        pvData: [],
        tableKey: 0
      }
    },
    created () {
      this.getList();
    },
    methods: {
      handleUpdate(row) {
        console.log(row)
      },
      getList() {
        this.listLoading = true;
        fetchList(this.listQuery).then(response => {
          this.list = response.data.items;
          this.total = response.data.total;
          this.listLoading = false;
        })
      },
//      分页
      handleSizeChange(val) {
        this.listQuery.limit = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.page = val;
        this.getList();
      }
    }
  }
</script>
